﻿using NineSeas.Models;
using Orchard;
using Orchard.Core.Contents;
using Orchard.Localization;
using Orchard.Mvc;
using Orchard.Security;
using Orchard.Themes;
using Orchard.ContentManagement;
using System.Web.Mvc;
using System;


namespace NineSeas.Controllers
{
    public class AuthoringController: Controller
    {
        private readonly IAuthenticationService _authenticationService;
        private readonly IOrchardServices _services;
        private Localizer T { get; set; }

        public AuthoringController(IOrchardServices services, IAuthenticationService authenticationService)
        {
            this._services = services;
            this._authenticationService = authenticationService;
            T = NullLocalizer.Instance;
        }

        [Themed]
        public ActionResult Index()
        {
            if (!_services.Authorizer.Authorize(Permissions.AddBooks, T("You do not have the permission to this page.")))
            {
                return Redirect("~/");
            }
            var user = _authenticationService.GetAuthenticatedUser();

            var profile = user.As<AuthorProfilePart>();

            //var author = user.ContentItem.As<BookAuthorPart>();
            return new ShapeResult(this, _services.New.Authoring_Index(
                    HasProfile: profile != null && !String.IsNullOrEmpty(profile.DisplayName)
                ));
        }
        public ActionResult Statistics()
        {
            return new ShapeResult(this, _services.New.Authoring_Statistics());
        }
        public ActionResult Ads()
        {
            return new ShapeResult(this, _services.New.Authoring_Ads());
        }
    }
}